//
//  TJTemplateCell.m
//  BaoDian
//
//  Created by mac on 2024/7/24.
//

#import "TJTemplateCell.h"
#import "TJVideoCoverDownloader.h"

@interface TJTemplateCell()

@property (nonatomic, weak) UIImageView *imageView;

@end

@implementation TJTemplateCell

- (void)settingSubView {
    [super settingSubView];
    
    
    UIImageView *imageView = [UIImageView addToView:self.contentView];
    imageView.addCornerRadius(12);
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    imageView.backgroundColor = UIColorMake(0xCECECD);
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.offset(0);
    }];
    _imageView = imageView;
    
    UIImageView *playerIconView = [UIImageView addToView:imageView];
    playerIconView.image = [UIImage imageNamed:@"videoPlayer_icon"];
    [playerIconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.offset(0);
    }];
}

- (void)setModel:(TJTemplateModel *)model {
    _model = model;
    
            if (model.type.intValue == 1) {
                [self.imageView tj_setImageWithUrl:model.coverUrl];
            } else {
                if (isEmptyString(model.videoUrl)) {
                    self.imageView.image = nil;
                } else {
                    [[TJVideoCoverDownloader shareDownLoader] downloadWithUrl:model.videoUrl completion:^(UIImage * _Nullable thumbnail) {
                        self.imageView.image = thumbnail;
                    }];
                }
            }
 
}

@end
